using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using CristiPotlog.Controls;
using ICP_MS.Plugin.Tune.Properties;
using ZedGraph;

namespace ICP_MS.Plugin.Tune;

public class FormAutoTuneStandard : Form
{
	private AutoTuneExperiment experiment = null;

	private Thread threadUptake = null;

	private Thread threadTune = null;

	private bool pauseUptake = false;

	private string[] LimitType = new string[5]
	{
		Lang.Txt("Tune.None"),
		Lang.Txt("Tune.Max"),
		Lang.Txt("Tune.Min"),
		Lang.Txt("Tune.More"),
		Lang.Txt("Tune.Less")
	};

	public static bool IsOpen;

	public string fileName = "";

	private IContainer components = null;

	private Wizard wizard1;

	private WizardPage wizardWelcom;

	private WizardPage wizardSample;

	private WizardPage wizardFinish;

	private WizardPage wizardHistory;

	private WizardPage wizardUptake;

	private System.Windows.Forms.Label lblSolution;

	private System.Windows.Forms.Label label2;

	private System.Windows.Forms.Label label1;

	private ProgressBar barUptake;

	private System.Windows.Forms.Label label3;

	private WizardPage wizardAcquisition;

	private System.Windows.Forms.Label label4;

	private Button btnContinue;

	private Button btnPause;

	private System.Windows.Forms.Label lblUptake;

	private Button btnResult;

	private Button btnLog;

	private System.Windows.Forms.Label txtResult;

	private PictureBox picError;

	private ListBox listBoxTune;

	private ZedGraphControl graphMass;

	private Button btnSkip;

	private Button btnExport;

	private GroupBox groupBox1;

	private System.Windows.Forms.Label label8;

	private System.Windows.Forms.Label label7;

	private System.Windows.Forms.Label label6;

	private System.Windows.Forms.Label label9;

	private System.Windows.Forms.Label label5;

	private CheckBox checkBox6;

	private CheckBox checkBox5;

	private CheckBox checkBox4;

	private CheckBox checkBox3;

	private CheckBox checkBox2;

	public FormAutoTuneStandard()
	{
		InitializeComponent();
		wizard1.CancelText = Lang.Txt("Tune.Cancel");
		wizard1.OkText = Lang.Txt("Tune.OK");
		wizard1.NextText = Lang.Txt("Tune.Next");
		wizard1.BackText = Lang.Txt("Tune.Back");
	}

	private void FormAutoTuneRunWizard_Load(object sender, EventArgs e)
	{
		base.StartPosition = FormStartPosition.CenterParent;
		Win32API.SetTopMost((Control)this);
		IsOpen = true;
		graphMass.GraphPane.Title.Text = Lang.Txt("Tune.TuningCurve");
		graphMass.GraphPane.XAxis.Title.Text = "";
		graphMass.GraphPane.YAxis.Title.Text = Lang.Txt("AddFormSpectrums.Intensity");
		graphMass.GraphPane.Y2Axis.IsVisible = true;
		graphMass.IsShowPointValues = true;
		experiment = AutoTuneExperiment.LoadConfig(Lang.Txt("Tune.StandardMode"));
		if (experiment == null)
		{
			MessageBox.Show(Lang.Txt("Tune.Text54"), Lang.Txt("AddFormIgnite.Warn"));
			Close();
		}
		ApplyResources();
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("ADDTune.Tune.AutoTune");
		wizardWelcom.Title = Lang.Txt("Tune.Text47");
		wizardWelcom.Description = Lang.Txt("Tune.Text18");
		wizardHistory.Title = Lang.Txt("Tune.Mesg7");
		wizardHistory.Description = Lang.Txt("Tune.Text48");
		checkBox2.Text = Lang.Txt("Tune.TorchLocation");
		checkBox3.Text = Lang.Txt("Tune.ICP");
		checkBox4.Text = Lang.Txt("Tune.LensGroup1");
		checkBox5.Text = Lang.Txt("Tune.LensGroup2");
		checkBox6.Text = Lang.Txt("Tune.Others");
		label9.Text = Lang.Txt("Tune.Text49");
		label5.Text = Lang.Txt("Tune.Text50");
		label6.Text = Lang.Txt("Tune.Text51");
		label7.Text = Lang.Txt("Tune.Text52");
		label8.Text = Lang.Txt("Tune.Text53");
		wizardSample.Title = Lang.Txt("Tune.Text22");
		wizardSample.Description = Lang.Txt("Tune.Text23");
		label1.Text = Lang.Txt("Tune.Text24");
		label2.Text = Lang.Txt("Tune.Text25");
		wizardUptake.Title = Lang.Txt("Tune.Text26");
		label3.Text = Lang.Txt("Tune.Text27");
		btnPause.Text = Lang.Txt("Tune.Pause");
		btnContinue.Text = Lang.Txt("Tune.Continue");
		label3.Text = Lang.Txt("Tune.Text27");
		btnPause.Text = Lang.Txt("Tune.Pause");
		btnContinue.Text = Lang.Txt("Tune.Continue");
		wizardAcquisition.Title = Lang.Txt("Tune.Text28");
		wizardAcquisition.Description = Lang.Txt("Tune.Text29");
		label4.Text = Lang.Txt("Tune.Text30");
		btnSkip.Text = Lang.Txt("Tune.Skip");
		wizardFinish.Title = Lang.Txt("Tune.Text31");
		wizardFinish.Description = Lang.Txt("Tune.Text32");
		btnLog.Text = Lang.Txt("Tune.Log");
		btnResult.Text = Lang.Txt("Tune.Result");
		btnExport.Text = Lang.Txt("Tune.DataExport");
	}

	private void FormAutoTuneRunWizard_FormClosed(object sender, FormClosedEventArgs e)
	{
		IsOpen = false;
	}

	private void wizard1_AfterSwitchPages(object sender, Wizard.AfterSwitchPagesEventArgs e)
	{
		WizardPage newPage = wizard1.Pages[e.NewIndex];
		switch (e.NewIndex)
		{
		case 0:
			break;
		case 1:
			experiment.SetConfig();
			break;
		case 2:
			ShowSolution();
			if (UserManager.CurrentUser.authority <= 1)
			{
				wizard1.BackEnabled = false;
			}
			break;
		case 3:
			if (Detector.Instance.ExperimentState != -1)
			{
				if (Detector.Instance.ExperimentState == 1)
				{
					MessageBox.Show(Lang.Txt("Tune.TipsText1"), Lang.Txt("AddFormIgnite.Warn"));
					break;
				}
				if (MessageBox.Show(Lang.Txt("Tune.TipsText2"), Lang.Txt("AddFormIgnite.Warn"), MessageBoxButtons.YesNo) != DialogResult.Yes)
				{
					break;
				}
				Detector.Instance.ExperimentStateChange(Detector.Instance.ExperimentState);
			}
			ShowUptake();
			break;
		case 4:
			experiment.EventTuneFinish += experiment_EventTuneFinish;
			experiment.EventTuneMsg += experiment_EventTuneMsg;
			experiment.EventPointMsg += experiment_PointEventMsg;
			ShowTune();
			wizard1.NextEnabled = false;
			wizard1.BackEnabled = false;
			break;
		case 5:
			ShowResults();
			wizard1.NextEnabled = false;
			wizard1.BackEnabled = false;
			break;
		}
	}

	private void wizard1_BeforeSwitchPages(object sender, Wizard.BeforeSwitchPagesEventArgs e)
	{
		WizardPage oldPage = wizard1.Pages[e.OldIndex];
		switch (e.OldIndex)
		{
		case 0:
			if (UserManager.CurrentUser.authority <= 1)
			{
				experiment = AutoTuneExperiment.LoadConfig("AutoTune");
				fileName = "AutoTune";
				e.NewIndex += 2;
			}
			break;
		case 1:
			if (!checkBox2.Checked && !checkBox3.Checked && !checkBox4.Checked && !checkBox5.Checked && !checkBox6.Checked)
			{
				MessageBox.Show(Lang.Txt("Tune.Text55"));
				e.Cancel = true;
			}
			break;
		case 2:
			break;
		case 3:
			if (threadUptake != null && threadUptake.IsAlive)
			{
				threadUptake.Abort();
				threadUptake = null;
			}
			break;
		case 4:
			experiment.EventTuneFinish += experiment_EventTuneFinish;
			experiment.EventTuneMsg += experiment_EventTuneMsg;
			break;
		}
	}

	private void wizard1_Cancel(object sender, CancelEventArgs e)
	{
		if (MessageBox.Show(Lang.Txt("Tune.Text15"), Lang.Txt("Tune.Text16"), MessageBoxButtons.YesNo) == DialogResult.No)
		{
			e.Cancel = true;
		}
		else if (threadUptake != null && threadUptake.IsAlive)
		{
			threadUptake.Abort();
			threadUptake = null;
		}
		else if (experiment != null && experiment.isTuning)
		{
			experiment.StopTune();
		}
	}

	private void wizard1_Finish(object sender, EventArgs e)
	{
		if (!experiment.TuneSucceed)
		{
			return;
		}
		string time = DateTime.Now.ToString();
		InstrumentConfig config = new InstrumentConfig();
		config.Description = experiment.Name;
		config.Time = time;
		config.Used = false;
		config.User = Environment.UserName;
		try
		{
			List<InstrumentConfig> instrumentconfigs = DataBase.Instance.GetAllInstrumentConfigs().ToList();
			instrumentconfigs.Sort((InstrumentConfig r1, InstrumentConfig r2) => r1.Time.CompareTo(r2.Time));
			if (instrumentconfigs.Find((InstrumentConfig r) => r.Description == experiment.Name) != null)
			{
				DataBase.Instance.DeleteInstrumentConfig(instrumentconfigs.Find((InstrumentConfig r) => r.Description == experiment.Name));
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog(Lang.Txt("Tune.Text33"), Lang.Txt("Tune.Text34"), ex.Message, (Severity)2);
		}
		if (DataBase.Instance.SaveInstrumentConfig(config))
		{
			X2Lens lens = LensManager.x2lens.Clone();
			lens.name = time;
			Platform plat = PlatManager.plat.Clone();
			plat.name = time;
			PlasmaPara plasma = PlasmaManager.plasma.Clone();
			plasma.Name = time;
			RFS rfs = RFManager.rfs.Clone();
			rfs.name = time;
			if (!DataBase.Instance.SaveX2Lens(lens) || !DataBase.Instance.SavePlatform(plat) || !DataBase.Instance.SavePlasma(plasma) || !DataBase.Instance.SaveRFS(rfs))
			{
				MessageBox.Show(Lang.Txt("Tune.Text35"));
			}
		}
		else
		{
			MessageBox.Show(Lang.Txt("Tune.Text36"));
		}
	}

	private void ShowSolution()
	{
		lblSolution.Text = experiment.Solution;
	}

	private void ShowUptake()
	{
		pauseUptake = false;
		btnPause.Enabled = true;
		btnContinue.Enabled = false;
		int tickCount = 40;
		threadUptake = new Thread((ThreadStart)delegate
		{
			while (tickCount > 0)
			{
				if (!pauseUptake)
				{
					tickCount--;
				}
				Invoke((MethodInvoker)delegate
				{
					barUptake.Value = tickCount;
					lblUptake.Text = $"{tickCount} s";
				});
				Thread.Sleep(1000);
			}
			wizard1.Next();
		});
		threadUptake.Start();
	}

	private void btnPause_Click(object sender, EventArgs e)
	{
		pauseUptake = true;
		btnContinue.Enabled = true;
		btnPause.Enabled = false;
	}

	private void btnContinue_Click(object sender, EventArgs e)
	{
		pauseUptake = false;
		btnPause.Enabled = true;
		btnContinue.Enabled = false;
	}

	private void ShowTune()
	{
		experiment.SetDefaultValue();
		experiment.StartTune();
	}

	private void experiment_EventTuneFinish(object sender, EventArgs e)
	{
		Invoke((MethodInvoker)delegate
		{
			wizard1.Next();
		});
	}

	private void experiment_EventTuneMsg(object sender, MsgEventArgs e)
	{
		Invoke((MethodInvoker)delegate
		{
			string[] points = e.Message.Split(':', ',');
			if (points != null && points.Count() > 0 && points[0] == "point")
			{
				Invoke((MethodInvoker)delegate
				{
					int count = graphMass.GraphPane.CurveList.Find((CurveItem r) => r.Label.Text == points[1]).Points.Count;
					PointPair pointPair = new PointPair(count, double.Parse(points.Last()));
					string text = "";
					for (int i = 2; i < points.Count(); i++)
					{
						text = text + points[i].ToString() + "\n";
					}
					pointPair.Tag = text;
					graphMass.GraphPane.CurveList.Find((CurveItem r) => r.Label.Text == points[1]).AddPoint(pointPair);
					graphMass.AxisChange();
					graphMass.Refresh();
				});
			}
			else
			{
				if (points != null && points.Count() > 0 && points[0] == "Stage")
				{
					AutoTuneExperiment.TuneStage tuneStage = experiment.Stages.Find((AutoTuneExperiment.TuneStage r) => r.StageName == points[1]);
					graphMass.GraphPane.CurveList.Clear();
					{
						foreach (AutoTuneExperiment.ParamConditon current in tuneStage.Params.Where((AutoTuneExperiment.ParamConditon p) => p.Type != 0))
						{
							if (current.Isotope != null)
							{
								LineItem lineItem = graphMass.GraphPane.AddCurve(current.Isotope.Symbol.ToString(), new PointPairList(), Color.Black, SymbolType.None);
								lineItem.IsY2Axis = current.Type != 1 && current.Type != 2;
							}
							else if (current.Ratio != null)
							{
								string label = $"{current.Ratio.Numerator.Symbol}/{current.Ratio.Denominator.Symbol}";
								LineItem lineItem2 = graphMass.GraphPane.AddCurve(label, new PointPairList(), Color.Red, SymbolType.None);
								lineItem2.IsY2Axis = current.Type != 1 && current.Type != 2;
							}
						}
						return;
					}
				}
				if (e.Message == "1")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text37");
				}
				else if (e.Message == "2")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text38");
				}
				else if (e.Message == "3.0")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text39");
				}
				else if (e.Message == "3.1")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text40");
				}
				else if (e.Message == "4.0")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text41");
				}
				else if (e.Message == "4.1")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text42");
				}
				else if (e.Message == "4.2")
				{
					graphMass.GraphPane.CurveList[0].Clear();
					graphMass.GraphPane.Title.Text = Lang.Txt("Tune.Text43");
				}
				else
				{
					listBoxTune.Items.Add(e.Message);
					listBoxTune.SelectedIndex = listBoxTune.Items.Count - 1;
				}
			}
		});
	}

	private void ShowResults()
	{
		if (!experiment.TuneSucceed)
		{
			picError.Visible = true;
			txtResult.ForeColor = Color.Red;
			txtResult.Text = Lang.Txt("Tune.Text44");
			return;
		}
		picError.Visible = false;
		txtResult.ForeColor = Color.Black;
		StringBuilder sb = new StringBuilder();
		foreach (AutoTuneExperiment.TuneStage stage in experiment.Stages)
		{
			if (!stage.Used)
			{
				continue;
			}
			sb.AppendLine(stage.StageName);
			sb.AppendLine("    Devices:");
			foreach (AutoTuneExperiment.DeviceCondition device in stage.Devices.Where((AutoTuneExperiment.DeviceCondition dev) => dev.Used))
			{
				sb.AppendLine($"      {device.Device}:{device.BestValue:0.00}");
			}
			sb.AppendLine();
			sb.AppendLine("    Results:");
			foreach (AutoTuneExperiment.ParamConditon para in stage.Params.Where((AutoTuneExperiment.ParamConditon p) => p.Type != 0))
			{
				sb.AppendLine($"       {para.Symbol}:{para.BestResult:0.000}");
			}
		}
		txtResult.Text = sb.ToString();
	}

	private void experiment_PointEventMsg(object sender, PointEventMsg e)
	{
		Invoke((MethodInvoker)delegate
		{
			PointPair point = new PointPair(graphMass.GraphPane.CurveList[0].Points.Count, e.Intensity)
			{
				Tag = $"{e.X}\n {e.Y}\n {e.Z}\n {e.Intensity}\n"
			};
			graphMass.GraphPane.CurveList[0].AddPoint(point);
			graphMass.AxisChange();
			graphMass.Refresh();
		});
	}

	private void btnLog_Click(object sender, EventArgs e)
	{
		string tmpName = Path.GetTempFileName();
		using (StreamWriter sw = new StreamWriter(tmpName))
		{
			StringBuilder sb = new StringBuilder();
			foreach (object item in listBoxTune.Items)
			{
				sb.AppendLine(item.ToString());
			}
			sw.WriteLine(sb.ToString());
		}
		Process.Start("notepad.exe", tmpName);
	}

	private void btnResult_Click(object sender, EventArgs e)
	{
		string tmpName = Path.GetTempFileName();
		using (StreamWriter sw = new StreamWriter(tmpName))
		{
			sw.Write(txtResult.Text);
		}
		Process.Start("notepad.exe", tmpName);
	}

	private void btnSkip_Click(object sender, EventArgs e)
	{
		experiment.Skip(bSkip: true);
	}

	private void wizardWelcom_Click(object sender, EventArgs e)
	{
	}

	private void btnExport_Click(object sender, EventArgs e)
	{
		string FileName = Application.StartupPath + "\\TestData\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".csv";
		using StreamWriter sw = new StreamWriter(FileName);
		try
		{
			sw.Write(Lang.Txt("Tune.Text45"));
			sw.Write(",");
			for (int k = 0; k < graphMass.GraphPane.CurveList.Count; k++)
			{
				sw.Write(graphMass.GraphPane.CurveList[k].Tag.ToString());
				sw.Write(",");
			}
			sw.WriteLine();
			for (int i = 0; i < graphMass.GraphPane.CurveList[0].Points.Count; i++)
			{
				sw.Write(graphMass.GraphPane.CurveList[0].Points[i].X);
				sw.Write(",");
				for (int j = 0; j < graphMass.GraphPane.CurveList.Count; j++)
				{
					sw.Write(graphMass.GraphPane.CurveList[j].Points[i].Y);
					sw.Write(",");
				}
				sw.WriteLine();
			}
			MessageBox.Show("Success！", "Info");
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void graphMass_Load(object sender, EventArgs e)
	{
	}

	private void checkBox2_CheckedChanged(object sender, EventArgs e)
	{
		experiment.Stages[0].Selected = checkBox2.Checked;
	}

	private void checkBox3_CheckedChanged(object sender, EventArgs e)
	{
		experiment.Stages[1].Selected = checkBox3.Checked;
		experiment.Stages[2].Selected = checkBox3.Checked;
	}

	private void checkBox4_CheckedChanged(object sender, EventArgs e)
	{
		experiment.Stages[3].Selected = checkBox4.Checked;
		experiment.Stages[4].Selected = checkBox4.Checked;
	}

	private void checkBox5_CheckedChanged(object sender, EventArgs e)
	{
		experiment.Stages[5].Selected = checkBox5.Checked;
		experiment.Stages[6].Selected = checkBox5.Checked;
		experiment.Stages[7].Selected = checkBox5.Checked;
	}

	private void checkBox6_CheckedChanged(object sender, EventArgs e)
	{
		experiment.Stages[8].Selected = checkBox6.Checked;
		experiment.Stages[9].Selected = checkBox6.Checked;
		experiment.Stages[10].Selected = checkBox6.Checked;
		experiment.Stages[11].Selected = checkBox6.Checked;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		this.wizard1 = new CristiPotlog.Controls.Wizard();
		this.wizardHistory = new CristiPotlog.Controls.WizardPage();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.label8 = new System.Windows.Forms.Label();
		this.label7 = new System.Windows.Forms.Label();
		this.label6 = new System.Windows.Forms.Label();
		this.label9 = new System.Windows.Forms.Label();
		this.label5 = new System.Windows.Forms.Label();
		this.checkBox6 = new System.Windows.Forms.CheckBox();
		this.checkBox5 = new System.Windows.Forms.CheckBox();
		this.checkBox4 = new System.Windows.Forms.CheckBox();
		this.checkBox3 = new System.Windows.Forms.CheckBox();
		this.checkBox2 = new System.Windows.Forms.CheckBox();
		this.wizardWelcom = new CristiPotlog.Controls.WizardPage();
		this.wizardSample = new CristiPotlog.Controls.WizardPage();
		this.lblSolution = new System.Windows.Forms.Label();
		this.label2 = new System.Windows.Forms.Label();
		this.label1 = new System.Windows.Forms.Label();
		this.wizardUptake = new CristiPotlog.Controls.WizardPage();
		this.btnContinue = new System.Windows.Forms.Button();
		this.btnPause = new System.Windows.Forms.Button();
		this.lblUptake = new System.Windows.Forms.Label();
		this.barUptake = new System.Windows.Forms.ProgressBar();
		this.label3 = new System.Windows.Forms.Label();
		this.wizardAcquisition = new CristiPotlog.Controls.WizardPage();
		this.btnSkip = new System.Windows.Forms.Button();
		this.graphMass = new ZedGraph.ZedGraphControl();
		this.listBoxTune = new System.Windows.Forms.ListBox();
		this.label4 = new System.Windows.Forms.Label();
		this.wizardFinish = new CristiPotlog.Controls.WizardPage();
		this.btnExport = new System.Windows.Forms.Button();
		this.txtResult = new System.Windows.Forms.Label();
		this.picError = new System.Windows.Forms.PictureBox();
		this.btnResult = new System.Windows.Forms.Button();
		this.btnLog = new System.Windows.Forms.Button();
		this.wizard1.SuspendLayout();
		this.wizardHistory.SuspendLayout();
		this.groupBox1.SuspendLayout();
		this.wizardSample.SuspendLayout();
		this.wizardUptake.SuspendLayout();
		this.wizardAcquisition.SuspendLayout();
		this.wizardFinish.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.picError).BeginInit();
		base.SuspendLayout();
		this.wizard1.AutoSize = true;
		this.wizard1.Controls.Add(this.wizardHistory);
		this.wizard1.Controls.Add(this.wizardWelcom);
		this.wizard1.Controls.Add(this.wizardFinish);
		this.wizard1.Controls.Add(this.wizardAcquisition);
		this.wizard1.Controls.Add(this.wizardUptake);
		this.wizard1.Controls.Add(this.wizardSample);
		this.wizard1.HeaderImage = ICP_MS.Plugin.Tune.Properties.Resources.wizardHeader;
		this.wizard1.Location = new System.Drawing.Point(0, 0);
		this.wizard1.Margin = new System.Windows.Forms.Padding(4);
		this.wizard1.Name = "wizard1";
		this.wizard1.Pages.AddRange(new CristiPotlog.Controls.WizardPage[6] { this.wizardWelcom, this.wizardHistory, this.wizardSample, this.wizardUptake, this.wizardAcquisition, this.wizardFinish });
		this.wizard1.Size = new System.Drawing.Size(1088, 564);
		this.wizard1.TabIndex = 0;
		this.wizard1.WelcomeImage = ICP_MS.Plugin.Tune.Properties.Resources.wizardWelcom;
		this.wizard1.BeforeSwitchPages += new CristiPotlog.Controls.Wizard.BeforeSwitchPagesEventHandler(wizard1_BeforeSwitchPages);
		this.wizard1.AfterSwitchPages += new CristiPotlog.Controls.Wizard.AfterSwitchPagesEventHandler(wizard1_AfterSwitchPages);
		this.wizard1.Cancel += new System.ComponentModel.CancelEventHandler(wizard1_Cancel);
		this.wizard1.Finish += new System.EventHandler(wizard1_Finish);
		this.wizardHistory.Controls.Add(this.groupBox1);
		this.wizardHistory.Description = "选择调谐选项";
		this.wizardHistory.Location = new System.Drawing.Point(0, 0);
		this.wizardHistory.Margin = new System.Windows.Forms.Padding(4);
		this.wizardHistory.Name = "wizardHistory";
		this.wizardHistory.Size = new System.Drawing.Size(1088, 516);
		this.wizardHistory.TabIndex = 17;
		this.wizardHistory.Title = "选择历史配置";
		this.groupBox1.Controls.Add(this.label8);
		this.groupBox1.Controls.Add(this.label7);
		this.groupBox1.Controls.Add(this.label6);
		this.groupBox1.Controls.Add(this.label9);
		this.groupBox1.Controls.Add(this.label5);
		this.groupBox1.Controls.Add(this.checkBox6);
		this.groupBox1.Controls.Add(this.checkBox5);
		this.groupBox1.Controls.Add(this.checkBox4);
		this.groupBox1.Controls.Add(this.checkBox3);
		this.groupBox1.Controls.Add(this.checkBox2);
		this.groupBox1.Location = new System.Drawing.Point(63, 105);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(1000, 274);
		this.groupBox1.TabIndex = 2;
		this.groupBox1.TabStop = false;
		this.label8.AutoSize = true;
		this.label8.Location = new System.Drawing.Point(237, 210);
		this.label8.Name = "label8";
		this.label8.Size = new System.Drawing.Size(353, 15);
		this.label8.TabIndex = 2;
		this.label8.Text = "(六极杆偏置、四极杆偏置、预杆偏置、六极杆系数)";
		this.label7.AutoSize = true;
		this.label7.Location = new System.Drawing.Point(228, 166);
		this.label7.Name = "label7";
		this.label7.Size = new System.Drawing.Size(177, 15);
		this.label7.TabIndex = 2;
		this.label7.Text = "（聚焦、D1+D2、DA+QE）";
		this.label6.AutoSize = true;
		this.label6.Location = new System.Drawing.Point(228, 124);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(146, 15);
		this.label6.TabIndex = 2;
		this.label6.Text = "（提取+L1+L2、L3）";
		this.label9.AutoSize = true;
		this.label9.Location = new System.Drawing.Point(228, 38);
		this.label9.Name = "label9";
		this.label9.Size = new System.Drawing.Size(165, 15);
		this.label9.TabIndex = 2;
		this.label9.Text = "（水平位置+垂直位置）";
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(228, 81);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(180, 15);
		this.label5.TabIndex = 2;
		this.label5.Text = "（功率+载气、采样深度）";
		this.checkBox6.AutoSize = true;
		this.checkBox6.Checked = true;
		this.checkBox6.CheckState = System.Windows.Forms.CheckState.Checked;
		this.checkBox6.Location = new System.Drawing.Point(27, 206);
		this.checkBox6.Name = "checkBox6";
		this.checkBox6.Size = new System.Drawing.Size(89, 19);
		this.checkBox6.TabIndex = 1;
		this.checkBox6.Text = "其他参数";
		this.checkBox6.UseVisualStyleBackColor = true;
		this.checkBox6.CheckedChanged += new System.EventHandler(checkBox6_CheckedChanged);
		this.checkBox5.AutoSize = true;
		this.checkBox5.Checked = true;
		this.checkBox5.CheckState = System.Windows.Forms.CheckState.Checked;
		this.checkBox5.Location = new System.Drawing.Point(27, 165);
		this.checkBox5.Name = "checkBox5";
		this.checkBox5.Size = new System.Drawing.Size(82, 19);
		this.checkBox5.TabIndex = 1;
		this.checkBox5.Text = "透镜组2";
		this.checkBox5.UseVisualStyleBackColor = true;
		this.checkBox5.CheckedChanged += new System.EventHandler(checkBox5_CheckedChanged);
		this.checkBox4.AutoSize = true;
		this.checkBox4.Checked = true;
		this.checkBox4.CheckState = System.Windows.Forms.CheckState.Checked;
		this.checkBox4.Location = new System.Drawing.Point(27, 123);
		this.checkBox4.Name = "checkBox4";
		this.checkBox4.Size = new System.Drawing.Size(82, 19);
		this.checkBox4.TabIndex = 1;
		this.checkBox4.Text = "透镜组1";
		this.checkBox4.UseVisualStyleBackColor = true;
		this.checkBox4.CheckedChanged += new System.EventHandler(checkBox4_CheckedChanged);
		this.checkBox3.AutoSize = true;
		this.checkBox3.Checked = true;
		this.checkBox3.CheckState = System.Windows.Forms.CheckState.Checked;
		this.checkBox3.Location = new System.Drawing.Point(27, 80);
		this.checkBox3.Name = "checkBox3";
		this.checkBox3.Size = new System.Drawing.Size(68, 19);
		this.checkBox3.TabIndex = 1;
		this.checkBox3.Text = "ICP源";
		this.checkBox3.UseVisualStyleBackColor = true;
		this.checkBox3.CheckedChanged += new System.EventHandler(checkBox3_CheckedChanged);
		this.checkBox2.AutoSize = true;
		this.checkBox2.Checked = true;
		this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
		this.checkBox2.Location = new System.Drawing.Point(27, 37);
		this.checkBox2.Name = "checkBox2";
		this.checkBox2.Size = new System.Drawing.Size(89, 19);
		this.checkBox2.TabIndex = 1;
		this.checkBox2.Text = "炬管位置";
		this.checkBox2.UseVisualStyleBackColor = true;
		this.checkBox2.CheckedChanged += new System.EventHandler(checkBox2_CheckedChanged);
		this.wizardWelcom.Description = "使用这个向导逐步完成自动调谐";
		this.wizardWelcom.Location = new System.Drawing.Point(0, 0);
		this.wizardWelcom.Margin = new System.Windows.Forms.Padding(4);
		this.wizardWelcom.Name = "wizardWelcom";
		this.wizardWelcom.Size = new System.Drawing.Size(1088, 516);
		this.wizardWelcom.Style = CristiPotlog.Controls.WizardPageStyle.Welcome;
		this.wizardWelcom.TabIndex = 10;
		this.wizardWelcom.Title = "标准模式调谐配置";
		this.wizardWelcom.Click += new System.EventHandler(wizardWelcom_Click);
		this.wizardSample.Controls.Add(this.lblSolution);
		this.wizardSample.Controls.Add(this.label2);
		this.wizardSample.Controls.Add(this.label1);
		this.wizardSample.Description = "准备样品，进样";
		this.wizardSample.Location = new System.Drawing.Point(0, 0);
		this.wizardSample.Margin = new System.Windows.Forms.Padding(4);
		this.wizardSample.Name = "wizardSample";
		this.wizardSample.Size = new System.Drawing.Size(428, 208);
		this.wizardSample.TabIndex = 14;
		this.wizardSample.Title = "进样";
		this.lblSolution.AutoSize = true;
		this.lblSolution.Location = new System.Drawing.Point(381, 227);
		this.lblSolution.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.lblSolution.Name = "lblSolution";
		this.lblSolution.Size = new System.Drawing.Size(0, 15);
		this.lblSolution.TabIndex = 2;
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(327, 192);
		this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(82, 15);
		this.label2.TabIndex = 1;
		this.label2.Text = "溶液要求：";
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(327, 140);
		this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(308, 15);
		this.label1.TabIndex = 0;
		this.label1.Text = "将进样管放入溶液后，点击 下一步 提升溶液";
		this.wizardUptake.Controls.Add(this.btnContinue);
		this.wizardUptake.Controls.Add(this.btnPause);
		this.wizardUptake.Controls.Add(this.lblUptake);
		this.wizardUptake.Controls.Add(this.barUptake);
		this.wizardUptake.Controls.Add(this.label3);
		this.wizardUptake.Location = new System.Drawing.Point(0, 0);
		this.wizardUptake.Margin = new System.Windows.Forms.Padding(4);
		this.wizardUptake.Name = "wizardUptake";
		this.wizardUptake.Size = new System.Drawing.Size(428, 208);
		this.wizardUptake.TabIndex = 22;
		this.wizardUptake.Title = "提升溶液";
		this.btnContinue.Location = new System.Drawing.Point(494, 256);
		this.btnContinue.Margin = new System.Windows.Forms.Padding(4);
		this.btnContinue.Name = "btnContinue";
		this.btnContinue.Size = new System.Drawing.Size(100, 29);
		this.btnContinue.TabIndex = 4;
		this.btnContinue.Text = "继续";
		this.btnContinue.UseVisualStyleBackColor = true;
		this.btnContinue.Click += new System.EventHandler(btnContinue_Click);
		this.btnPause.Location = new System.Drawing.Point(344, 256);
		this.btnPause.Margin = new System.Windows.Forms.Padding(4);
		this.btnPause.Name = "btnPause";
		this.btnPause.Size = new System.Drawing.Size(100, 29);
		this.btnPause.TabIndex = 3;
		this.btnPause.Text = "暂停";
		this.btnPause.UseVisualStyleBackColor = true;
		this.btnPause.Click += new System.EventHandler(btnPause_Click);
		this.lblUptake.AutoSize = true;
		this.lblUptake.Location = new System.Drawing.Point(450, 218);
		this.lblUptake.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.lblUptake.Name = "lblUptake";
		this.lblUptake.Size = new System.Drawing.Size(39, 15);
		this.lblUptake.TabIndex = 2;
		this.lblUptake.Text = "40 s";
		this.barUptake.Location = new System.Drawing.Point(239, 171);
		this.barUptake.Margin = new System.Windows.Forms.Padding(4);
		this.barUptake.Maximum = 40;
		this.barUptake.Name = "barUptake";
		this.barUptake.Size = new System.Drawing.Size(496, 29);
		this.barUptake.Step = 1;
		this.barUptake.TabIndex = 1;
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(199, 126);
		this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(353, 15);
		this.label3.TabIndex = 0;
		this.label3.Text = "提升溶液，点击 下一步 跳过此步骤，直接开始调谐";
		this.wizardAcquisition.Controls.Add(this.btnSkip);
		this.wizardAcquisition.Controls.Add(this.graphMass);
		this.wizardAcquisition.Controls.Add(this.listBoxTune);
		this.wizardAcquisition.Controls.Add(this.label4);
		this.wizardAcquisition.Description = "采集数据并调谐硬件";
		this.wizardAcquisition.Location = new System.Drawing.Point(0, 0);
		this.wizardAcquisition.Margin = new System.Windows.Forms.Padding(4);
		this.wizardAcquisition.Name = "wizardAcquisition";
		this.wizardAcquisition.Size = new System.Drawing.Size(428, 208);
		this.wizardAcquisition.TabIndex = 23;
		this.wizardAcquisition.Title = "开始调谐";
		this.btnSkip.Location = new System.Drawing.Point(90, 489);
		this.btnSkip.Name = "btnSkip";
		this.btnSkip.Size = new System.Drawing.Size(75, 23);
		this.btnSkip.TabIndex = 5;
		this.btnSkip.Text = "跳过";
		this.btnSkip.UseVisualStyleBackColor = true;
		this.btnSkip.Click += new System.EventHandler(btnSkip_Click);
		this.graphMass.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
		this.graphMass.Location = new System.Drawing.Point(332, 76);
		this.graphMass.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
		this.graphMass.Name = "graphMass";
		this.graphMass.ScrollGrace = 0.0;
		this.graphMass.ScrollMaxX = 0.0;
		this.graphMass.ScrollMaxY = 0.0;
		this.graphMass.ScrollMaxY2 = 0.0;
		this.graphMass.ScrollMinX = 0.0;
		this.graphMass.ScrollMinY = 0.0;
		this.graphMass.ScrollMinY2 = 0.0;
		this.graphMass.Size = new System.Drawing.Size(742, 436);
		this.graphMass.TabIndex = 4;
		this.graphMass.Load += new System.EventHandler(graphMass_Load);
		this.listBoxTune.FormattingEnabled = true;
		this.listBoxTune.ItemHeight = 15;
		this.listBoxTune.Location = new System.Drawing.Point(16, 95);
		this.listBoxTune.Margin = new System.Windows.Forms.Padding(4);
		this.listBoxTune.Name = "listBoxTune";
		this.listBoxTune.Size = new System.Drawing.Size(307, 364);
		this.listBoxTune.TabIndex = 1;
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(13, 76);
		this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(82, 15);
		this.label4.TabIndex = 0;
		this.label4.Text = "调谐状态：";
		this.wizardFinish.Controls.Add(this.btnExport);
		this.wizardFinish.Controls.Add(this.txtResult);
		this.wizardFinish.Controls.Add(this.picError);
		this.wizardFinish.Controls.Add(this.btnResult);
		this.wizardFinish.Controls.Add(this.btnLog);
		this.wizardFinish.Description = "点击 OK 完成设置";
		this.wizardFinish.Location = new System.Drawing.Point(0, 0);
		this.wizardFinish.Margin = new System.Windows.Forms.Padding(4);
		this.wizardFinish.Name = "wizardFinish";
		this.wizardFinish.Size = new System.Drawing.Size(1088, 516);
		this.wizardFinish.Style = CristiPotlog.Controls.WizardPageStyle.Finish;
		this.wizardFinish.TabIndex = 15;
		this.wizardFinish.Title = "完成";
		this.btnExport.Location = new System.Drawing.Point(563, 330);
		this.btnExport.Name = "btnExport";
		this.btnExport.Size = new System.Drawing.Size(101, 28);
		this.btnExport.TabIndex = 5;
		this.btnExport.Text = "数据导出";
		this.btnExport.UseVisualStyleBackColor = true;
		this.btnExport.Click += new System.EventHandler(btnExport_Click);
		this.txtResult.Location = new System.Drawing.Point(240, 118);
		this.txtResult.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.txtResult.Name = "txtResult";
		this.txtResult.Size = new System.Drawing.Size(638, 199);
		this.txtResult.TabIndex = 4;
		this.picError.BackColor = System.Drawing.Color.Transparent;
		this.picError.Image = ICP_MS.Plugin.Tune.Properties.Resources.Bug;
		this.picError.Location = new System.Drawing.Point(243, 85);
		this.picError.Margin = new System.Windows.Forms.Padding(4);
		this.picError.Name = "picError";
		this.picError.Size = new System.Drawing.Size(41, 29);
		this.picError.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
		this.picError.TabIndex = 3;
		this.picError.TabStop = false;
		this.picError.Visible = false;
		this.btnResult.Location = new System.Drawing.Point(381, 330);
		this.btnResult.Margin = new System.Windows.Forms.Padding(4);
		this.btnResult.Name = "btnResult";
		this.btnResult.Size = new System.Drawing.Size(100, 29);
		this.btnResult.TabIndex = 2;
		this.btnResult.Text = "结果";
		this.btnResult.UseVisualStyleBackColor = true;
		this.btnResult.Click += new System.EventHandler(btnResult_Click);
		this.btnLog.Location = new System.Drawing.Point(259, 330);
		this.btnLog.Margin = new System.Windows.Forms.Padding(4);
		this.btnLog.Name = "btnLog";
		this.btnLog.Size = new System.Drawing.Size(100, 29);
		this.btnLog.TabIndex = 1;
		this.btnLog.Text = "日志";
		this.btnLog.UseVisualStyleBackColor = true;
		this.btnLog.Click += new System.EventHandler(btnLog_Click);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
		base.ClientSize = new System.Drawing.Size(1088, 564);
		base.Controls.Add(this.wizard1);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
		base.Margin = new System.Windows.Forms.Padding(4);
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "FormAutoTuneStandard";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "自动调谐";
		base.FormClosed += new System.Windows.Forms.FormClosedEventHandler(FormAutoTuneRunWizard_FormClosed);
		base.Load += new System.EventHandler(FormAutoTuneRunWizard_Load);
		this.wizard1.ResumeLayout(false);
		this.wizardHistory.ResumeLayout(false);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		this.wizardSample.ResumeLayout(false);
		this.wizardSample.PerformLayout();
		this.wizardUptake.ResumeLayout(false);
		this.wizardUptake.PerformLayout();
		this.wizardAcquisition.ResumeLayout(false);
		this.wizardAcquisition.PerformLayout();
		this.wizardFinish.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.picError).EndInit();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
